package com.atguigu02.project;

public class CustomerList {
    public Customer[] customers;
   public int total=0;

    public CustomerList(int totalCustomer){
        customers=new Customer[totalCustomer];
    }

    public boolean addCustomer(Customer customer){
        if(total>=10){
            return false;
        }else{
            customers[total]=customer;
            total++;
        }
        return true;
    }

    public boolean repalceCustomer(int index,Customer cust){
        if(index<0||index>total){
            return false;
        }else{
           customers[index]=cust;
        }
        return true;
    }

    public boolean deleteCustomer(int index){
        if(index<0||index>total){
            return false;
        }else{
            for(int i=index;i<total-1;i++){
                customers[i]=customers[i+1];
            }
            customers[--total]=null;
            return  true;
        }
    }

    public Customer[] getAllCustomers() {
       //不能直接返回Customers因为会有空值
        Customer[] cus=new Customer[total];
        for (int i = 0; i <total ; i++) {
            cus[i]=customers[i];
        }
        return cus;
    }

    public Customer getCusomer(int index){
        if(index<0||index>total){
            return null;
        }
        return customers[index];
    }

    public int getTotal(){
        return total;
    }
}
